<template>
  <div>
    <el-form ref="dataForm" >
      <el-form-item label="id">
        <el-input v-model.trim="id" id="1" disabled></el-input>
      </el-form-item>
      <el-form-item label="账号">
        <el-input v-model.trim="account" id="2"/>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model.trim="password" id="3"/>
      </el-form-item>
      <el-form-item label="身份">
        <el-input v-model.trim="identity" id="4" disabled/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submit()">更改信息</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<style>
</style>
<script>
  import ECharts from 'vue-echarts/components/ECharts.vue'
  import 'echarts/lib/chart/line'
  import 'echarts/lib/component/tooltip'
  import 'echarts/lib/component/polar'
  import 'echarts/lib/component/legend'
  import 'echarts/lib/component/title'
  import 'echarts/theme/dark'
  import 'echarts/lib/chart/bar'
  import {getRequest, putRequest, putRequestBody} from '../utils/api'
  export default{
    components: {
      'chart': ECharts
    },
    mounted: function () {
      let user = sessionStorage.getItem("user");
      if (user != null) {
        this.currentUser= JSON.parse(user);
        this.userId=this.currentUser[0].userId;
        this.id=this.userId;
        this.account=this.currentUser[0].account;
        this.password=this.currentUser[0].password;
        this.identity=this.currentUser[0].identity;
        console.log(this.userId);
      }
    },
    methods: {
      submit() {
        let newId =  document.getElementById('1').value;
        let newAccount=document.getElementById('2').value;
        let newPassword=document.getElementById('3').value;
        let newIdentity=document.getElementById('4').value;
        let newUser=JSON.stringify({userId:newId,account:newAccount,password:newPassword,identity:newIdentity})
        putRequestBody("/system/user", newUser).then((res) => {
          console.log(res);
          if (res.data.code == 200) {
            this.$message({
              type: "success",
              message: "更新信息成功！",
            });
          }
          else {
              this.$message({
                type: "error",
                message:
                        res.data.msg == null
                                ? "更新信息失败，请联系管理员！"
                                : res.data.msg,
              });
          }
        });
      },
    },
    data: function () {
      return {
        id: 123,
        account: "",
        password: "",
        identity: "",
        currentUser: {},
        user: {},
        userId: 123,
        session: '',
        sessionData: '',
      }
    }
  }
</script>
